<?php

class AvatarClass
{
	public $conn;
	private $imagesClass;
	private $simpleImage;
	
	function __construct()
	{
		/*$mysql = MySQLDatabaseClass::getInstance();
		$this->conn = $mysql->dbh; // */
		//$this->imagesClass = new ImagesClass;
		$this->simpleImage = new SimpleImageClass; 
	}
	
	function uploadAvatar($source, $destination, $newFileName, $newDim=250, $newDimThumb=100)
	{
		//$imagick = new imagick( $source['tmp_name'] );
		//$imagick->cropThumbnailImage( $newDim, $newDim );
		//$imagick->writeImage( $destination );
		file_exists($destination)     ? unlink($destination)     :"";
              //  file_exists($destinationThumb)? unlink($destinationThumb):"";
                
		$this->simpleImage->load($source['tmp_name']);
   		$this->simpleImage->resizeToWidth($newDim);
   		$this->simpleImage->save($destination);
		
		/*
		$this->simpleImage->load($source['tmp_name']);
   		$this->simpleImage->resize($newDimThumb, $newDimThumb);
   		$this->simpleImage->save($destinationThumb);
		//$this->imagesClass->scaleImage($source, $destination, $destinationThumb, $newFileName, $newWidth, $newWidthThumb); */
	}
	
	function uploadHeader($source, $destination, $destinationThumb, $newFileName, $newWidth=950, $newWidthThumb=300)
	{
		$this->simpleImage->load($source['tmp_name']);
   		$this->simpleImage->resizeToWidth($newWidth);
   		$this->simpleImage->save($destination);
		
		$this->simpleImage->load($source['tmp_name']);
   		$this->simpleImage->resizeToWidth($newWidthThumb);
   		$this->simpleImage->save($destinationThumb);
		//$this->imagesClass->scaleImage($source, $destination, $destinationThumb, $newFileName, $newWidth, $newWidthThumb);
	}
	
}